package team.pwy.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import team.pwy.util.ImageUtils;
import team.pwy.vo.Result;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("avatar")
public class AvatarController {
    @Autowired
    private ImageUtils imageUtils;

    @PostMapping
    public Result hello04(MultipartFile[] file, HttpServletRequest request) throws IOException {//大部分的前端文件上传的插件的名称都是file
        if(ObjectUtils.isEmpty(file)){
            return new Result("500","请选择上传的文件!");
        }
        Map<String, List<String>> uploadImagesUrl = imageUtils.uploadImages(file);
        return new Result("200","上传成功",uploadImagesUrl);
    }
}
